//可选属性

//不是所有属性都是必需的
interface IPerson2{
    name:string;
    age?:number;
}

function personPrint2(p:IPerson2){
    if(p.age===undefined){
        console.log(`${p.name}`);
    }else{
        console.log(`${p.name}:${p.age}`);
    }
    
}

let p21:IPerson2={name:'xiao'};
personPrint2(p21);

//采用类型推断
let p22:IPerson2={name:'ki',age:18,gender:'女'}as IPerson2;
personPrint2(p22);

let p23={name:'wang',age:20,gender:'男'};
personPrint2(p23);